import {createBrowserRouter, Navigate} from "react-router-dom";
import Home from "../page/Home/index.tsx";
import Login from "../page/Login";
import Register from "../page/Register";
import Admin from "../page/Admin";
import AccessEnum from "../constant/AccessEnum.ts";
import AuthRoute from "../components/AuthRoute";
import {NotPermission} from "../page/NoPermission/index.tsx";
import {NotPage} from "../page/NotPage/index.tsx";
import {UserInfo} from "../page/UserInfo/index.tsx";
import Searchs from "../page/Search/Search.tsx";
import {UserStatusChecker} from '../components/UserStatusChecker';
import {Chat} from "../page/Chat";
import BookCommunity from "../page/BookCommunity";
import BookActivities from "../page/BookActivities";
import ReadingRoom from "../page/ReadingRoom";
import Library from "../page/Library";
import BookDetail from "../page/BookDetail";
import SearchPage from '../pages/Search';
import RecommendBooks from '../pages/RecommendBooks';
import CommunityDetail from '../page/CommunityDetail';
import ReadingRoomDetail from '../page/ReadingRoom/Detail';
import MyBooks from '../page/MyBooks';
import MyBookList from '../page/MyBookList';
import MySeat from '../page/MySeat';
import EditProfile from '../page/UserInfo/EditProfile';
import CreatePost from '@/pages/CreatePost';
import HomeAdmin from '../page/Admin/Home';
import UserManagement from '../page/Admin/UserManagement';
import BookManagement from '../page/Admin/BookManagement';
import PostManagement from '../page/Admin/PostManagement';
import LikeManagement from '../page/Admin/LikeManagement';
import CommentManagement from '../page/Admin/CommentManagement';
import SeatManagement from '../page/Admin/SeatManagement';
import BorrowingManagement from '../page/Admin/BorrowingManagement';
import CarouselManagement from '../page/Admin/CarouselManagement';
import BookCategories from '../page/Admin/BookManagement/Categories';
import PostCategories from '../page/Admin/PostManagement/Categories';
import PostTags from '../page/Admin/PostManagement/Tags';

const routers = [
  {
    path: "/",
    element: (
      <>
        <UserStatusChecker />
        <Home></Home>
      </>
    ),
  },
  {
    path: "/home",
    element: (
      <>
        <UserStatusChecker />
        <Home></Home>
      </>
    )
  },
  {
    path: "/login",
    element: <Login></Login>,
  },
  {
    path: "/register",
    element: <Register></Register>,
  },
  {
    path: "/admin",
    element: (
      <AuthRoute access={AccessEnum.ADMIN}>
        <Admin />
      </AuthRoute>
    ),
    children: [
      {
        path: '',
        element: <Navigate to="home" replace />
      },
      {
        path: 'home',
        element: <HomeAdmin />,
        meta: {
          key: 'home',
          title: '管理首页'
        }
      },
      {
        path: 'carousel',
        element: <CarouselManagement />,
      },
      {
        path: 'users',
        element: <UserManagement />,
        meta: {
          key: 'user',
          title: '用户管理'
        }
      },
      {
        path: 'books/categories',
        element: <BookCategories />,
      },
      {
        path: 'books/management',
        element: <BookManagement />,
      },
      {
        path: 'posts/categories',
        element: <PostCategories />,
      },
      {
        path: 'posts/management',
        element: <PostManagement />,
      },
      {
        path: 'posts/tags',
        element: <PostTags />,
      },
      {
        path: 'comments',
        element: <CommentManagement />,
      },
      {
        path: 'seats',
        element: <SeatManagement />,
      },
      {
        path: 'borrowing',
        element: <BorrowingManagement />,
      },
    ],
  },
  {
    path: "/404",
    element: <NotPermission></NotPermission>
  },
  {
    path: "/userInfo/:id",
    element: (
      <>
        <UserStatusChecker />
        <AuthRoute access={AccessEnum.USER}>
        <UserInfo />
      </AuthRoute>
      </>
    ),
  },
  {
    path:"/chat",
    element: (
        <Chat></Chat>
    )
  },
  {
    path: "/book-community",
    element: (
      <>
        <UserStatusChecker />
        <BookCommunity />
      </>
    ),
  },
  {
    path: "/reading-room",
    element: (
      <>
        <UserStatusChecker />
        <ReadingRoom />
      </>
    ),
  },
  {
    path: "/library",
    element: (
      <>
        <UserStatusChecker />
        <Library />
      </>
    ),
  },
  {
    path: "/book/:id",
    element: (
      <>
        <UserStatusChecker />
        <BookDetail />
      </>
    ),
  },
  {
    path: "/search",
    element: <SearchPage />,
  },
  {
    path: "recommend-books",
    element: <RecommendBooks />,
  },
  {
    path: '/community/:sectionId/post/:postId',
    element: <CommunityDetail />
  },
  {
    path: '/reading-room/:id',
    element: <ReadingRoomDetail />
  },
  {
    path: '/my-books/:id',
    element: <MyBooks />,
  },
  {
    path: '/my-booklist/:id',
    element: <MyBookList />,
  },
  {
    path: '/my-seat/:id',
    element: <MySeat />,
  },
  {
    path: '/user/edit/:id',
    element: <EditProfile />
  },
  {
    path: '/create-post',
    element: <CreatePost />
  },
  {
    path: '/community/post/edit',
    element: <CreatePost />
  },
  {
    path: "*",
    element: <NotPage></NotPage>
  }
];

export default createBrowserRouter(routers);
